﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using BusinessLogic.BusinessEntity.Entities;
using BusinessLogic.Connectivity.Interfaces;
namespace BusinessLogic.Connectivity.Entities
{
	public class ServerProxy : ClientBase<IServerContract>, IServerContract
	{
		private ServerProxy() { }

		private ServerProxy(string endpointConfigurationName) :
			base(endpointConfigurationName) { }

		private ServerProxy(string endpointConfigurationName,
							  string remoteAddress) :
			base(endpointConfigurationName, remoteAddress) { }

		private ServerProxy(string endpointConfigurationName,
							  EndpointAddress remoteAddress) :
			base(endpointConfigurationName, remoteAddress) { }
		private ServerProxy(
						   System.ServiceModel.Channels.Binding binding,
							  EndpointAddress remoteAddress) :
			base(binding, remoteAddress) { }

		private static IServerContract instance;

		public static IServerContract Instance
		{
			get
			{
				if(instance == null)
				{
					instance = new ServerProxy("server");
				}

				return instance;
			}
		}

		public ServerResponse<DocumentEnvelope> ReceiveDocument(DocumentEnvelope envelope, string ticket)
		{
			return Channel.ReceiveDocument(envelope, ticket);
		}

		public ServerResponse<User> GetSessionTicket(Credentials credentials)
		{
			return Channel.GetSessionTicket(credentials);
		}

		public ServerResponse<IList<DocumentEnvelope>> GetSentEnvelopes(string ticket)
		{
			return Channel.GetSentEnvelopes(ticket);
		}

		public ServerResponse<IList<CurrencyConversion>> GetCurrencyConversions()
		{
			return Channel.GetCurrencyConversions();
		}

		public ServerResponse<CurrencyConversion> UpdateCurrencyConversion(CurrencyConversion conversion, string ticket)
		{
			return Channel.UpdateCurrencyConversion(conversion, ticket);
		}

		public ServerResponse<IList<RemittanceAdvice>> GetSentRemittanceAdvices(DateTime startDate, DateTime endDate, string ticket)
		{
			return Channel.GetSentRemittanceAdvices(startDate, endDate, ticket);
		}

		public ServerResponse<IList<RemittanceAdvice>> GetReceivedRemittanceAdvices(DateTime startDate, DateTime endDate, string ticket)
		{
			return Channel.GetReceivedRemittanceAdvices(startDate, endDate, ticket);
		}

		public ServerResponse<IList<Account>> GetClientAccounts(string ticket)
		{
			return Channel.GetClientAccounts(ticket);
		}

		public ServerResponse<Account> DeleteAccountById(int accountID, string ticket)
		{
			return Channel.DeleteAccountById(accountID, ticket);
		}

		public ServerResponse<Account> CreateAccount(Account account, string ticket)
		{
			return Channel.CreateAccount(account, ticket);
		}

		public ServerResponse<Account> ReplenishAccount(int accountID, decimal sumToAdd, string ticket)
		{
			return Channel.ReplenishAccount(accountID, sumToAdd, ticket);
		}

		public ServerResponse<IList<Account>> GetAllAccounts(string ticket)
		{
			return Channel.GetAllAccounts(ticket);
		}

		public ServerResponse<IList<Account>> GetAllAccountsForUser(string ticket)
		{
			return Channel.GetAllAccountsForUser(ticket);
		}

		public ServerResponse<User> CreateUser(User user, string sessionTicket)
		{
			return Channel.CreateUser(user, sessionTicket);
		}

		public ServerResponse<User> SetUserPublicKey(int userID, string publicKey, string sessionTicket)
		{
			return Channel.SetUserPublicKey(userID, publicKey, sessionTicket);
		}

		public ServerResponse<IList<User>> GetAllUsers(string sessionTicket)
		{
			return Channel.GetAllUsers(sessionTicket);
		}

		public ServerResponse<User> DeleteUser(int clientId, string sessionTicket)
		{
			return Channel.DeleteUser(clientId, sessionTicket);
		}

		public ServerResponse<User> UpdateUser(User user, string ticket)
		{
			return Channel.UpdateUser(user, ticket);
		}

		public ServerResponse<User> AssignRole(int userId, Role role, string ticket)
		{
			return Channel.AssignRole(userId, role, ticket);
		}

		public ServerResponse<User> DeleteRole(int userId, Role role, string ticket)
		{
			return Channel.DeleteRole(userId, role, ticket);
		}

		public ServerResponse<IDictionary<User, IList<Role>>> GetUsersRolePairs(string ticket)
		{
			return Channel.GetUsersRolePairs(ticket);
		}

		public ServerResponse<IList<Currency>> GetCurrencies()
		{
			return Channel.GetCurrencies();
		}

		public ServerResponse<IList<Role>> GetRoles()
		{
			return Channel.GetRoles();
		}

		public ServerResponse<IList<Role>> GetUserRoles(int userID, string ticket)
		{
			return Channel.GetUserRoles(userID, ticket);
		}

		public ServerResponse<Currency> DeleteCurrency(int currencyID, string ticket)
		{
			return Channel.DeleteCurrency(currencyID, ticket);
		}

		public ServerResponse<Currency> CreateCurrency(Currency currency, string ticket)
		{
			return Channel.CreateCurrency(currency, ticket);
		}
		
		public ServerResponse<CurrencyConversion> CreateCurrencyConversion(CurrencyConversion conversion, string ticket)
		{
			return Channel.CreateCurrencyConversion(conversion, ticket);
		}
	
		public ServerResponse<CurrencyConversion> DeleteCurrencyConversion(int currencyConversionID, string ticket)
		{
			return Channel.DeleteCurrencyConversion(currencyConversionID, ticket);
		}

		public ServerResponse<IList<DocumentEnvelope>> GetFilteredEnvelopes(string userName, DateTime periodStart, DateTime periodEnd, string ticket)
		{
			return Channel.GetFilteredEnvelopes(userName, periodStart, periodEnd, ticket);
		}
	}
}
